﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ReactReduxTool.UI.Dialog
{
    public partial class DialogInput : Form
    {

        public delegate void OnPublishContentListener(string content);

        private bool mIsMouseDown;
        private Point mMousePos;
        private OnPublishContentListener onPublishContentListener;

        public void SetOnPublishCntentListener(OnPublishContentListener onPublishContentListener)
        {
            this.onPublishContentListener = onPublishContentListener;
        }

        public DialogInput()
        {
            InitializeComponent();
        }

        public void InitDialog(string message)
        {
            txtMessage.Text = message;
        }

        private void DialogInput_MouseDown(object sender, MouseEventArgs e)
        {
            mMousePos = Cursor.Position;
            mIsMouseDown = true;
        }

        private void DialogInput_MouseMove(object sender, MouseEventArgs e)
        {
            if (mIsMouseDown && e.Button == MouseButtons.Left)
            {
                Point tempPos = Cursor.Position;
                this.Location = new Point(Location.X + (tempPos.X - mMousePos.X),Location.Y + (tempPos.Y - mMousePos.Y));
                mMousePos = tempPos;
            }
        }

        private void DialogInput_MouseUp(object sender, MouseEventArgs e)
        {
            mIsMouseDown = false;
            this.Focus();
        }

        private void imgClose_Click(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string content = txtReply.Text;
            if (content == null || content.Trim().Equals(""))
            {
                MessageBox.Show("请输入内容！");
                return;
            }
            this.onPublishContentListener(content);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
